<div id="main_container">

	{$oZoneHeader}
    
    <div class="main_content">
        {$oZoneTopMenu}
        <div class="center_content">  
            <div class="left_content">
                {$oZoneLeftMenu}
            </div>
    
            <div class="right_content">
        
                <h2>Statistiques formules</h2> 
                <form action="{jurl 'statistique~BoStatistique:index'}" method="post" name="trie" id="trie">
                    <fieldset>
                        <p>
                            <label>Date début</label>
                            <input type="text" id="datepicker1" value="{$dateDebut}" name="debut" /> &nbsp;
                            <label>Date fin</label>
                            <input type="text" id="datepicker2" value="{$dateFin}" name="fin" /> &nbsp;
                            
                        </p>
                        
                        <p id="btn-trie">
                            <a title="Annuler" href="#" class="bt_green" id="trier"><span class="bt_green_lft"></span><strong>Trier</strong><span class="bt_green_r"></span></a>
                        </p>
                        <p id="error" style="display:none;">Veuillez remplir les champs obligatoires .</p>
                     </fieldset>
                 </form>
                {if $dateDebut && $dateFin}
                    {if sizeof ($statParDate)}
                        <table id="rounded-corner" summary="2007 Major IT Companies' Profit">
                        <thead>
                            <tr>
                                <th scope="col" class="rounded">Date</th>
                                <th scope="col" class="rounded">Formule</th>
                                <th scope="col" class="rounded">Nombre d'annonces validées</th>
                                <th scope="col" class="rounded-q4">Total €</th>
                            </tr>
                        </thead>
                        <tbody>

                            {assign $nbrPhoto = 0}
                            {assign $totalNombreDetailParDate = 0}
                            {assign $totalEuroDetailParDate = 0}
                            {assign $totalNombreDetailParDateTmp = 0}
                            {assign $totalEuroDetailParDateTmp = 0}
                            {assign $j = 1}
                            {foreach $statParDate['tarif'] as $k=>$item}
                                {assign $totalNombreDetailParDate += $item->nombre}
                                {assign $totalEuroDetailParDate   += $item->Occas_Montantpaye * $item->nombre}
                                {assign $totalNombreDetailParDateTmp += $item->nombre}
                                {assign $totalEuroDetailParDateTmp   += $item->Occas_Montantpaye * $item->nombre}
                                {if sizeof ($statParDate['photo'])}
                                    {foreach $statParDate['photo'] as $itemPhoto}
                                        {if $itemPhoto->Occas_Montantpaye == $item->Occas_Montantpaye}
                                            {assign $nbrPhoto = $itemPhoto->nombre}
                                            {break}
                                        {/if}
                                    {/foreach}
                                {/if}
                              <tr class="{if $j%2 == 0 }hblue{/if}">
                                  <td>{$item->currentDate}</td>
                                  <!--<td>{*$item->Occas_Montantpaye*}€</td>-->
                                  <td>{$item->titre}</td>
                                  <td>{$item->nombre} (Photos : {$nbrPhoto})</td>
                                  <td>{$item->Occas_Montantpaye * $item->nombre}</td>
                              </tr>
                              {if (isset($statParDate['tarif'][$k+1]->currentDate) && $statParDate['tarif'][$k+1]->currentDate != $item->currentDate) || !isset($statParDate['tarif'][$k+1]->currentDate)}
                                    <tr>
                                      <td>&nbsp;</td>
                                      <td><b>Total : </td>
                                      <td><b>{$totalNombreDetailParDateTmp}</b></td>
                                      <td><b>{$totalEuroDetailParDateTmp}</b></td>

                                    </tr>
                                   <tr style="background:repeat scroll 0 0 #256C89 ;height:0px;overflow:hidden;  padding:0;font-size:1px;"><td style="height:0px; overflow:hidden;padding:0;" colspan="4">&nbsp;</td></tr>

                                    {assign $totalNombreDetailParDateTmp = 0}
                                    {assign $totalEuroDetailParDateTmp = 0}
                              {/if}
                              {assign $j++}
                            {/foreach}
                             <tr style="background:repeat scroll 0 0 #256C89; height:0px; overflow:hidden; padding:0;font-size:1px;"><td style="height:0px; overflow:hidden;padding:0;" colspan="4">&nbsp;</td></tr>
                              <tr>
                                  <td>&nbsp;</td>
                                  <td><b>Total : </td>
                                  <td><b>{$totalNombreDetailParDate}</b></td>
                                  <td><b>{$totalEuroDetailParDate}</b></td>
                              </tr>
                              </tbody>
                        </table>
                    {else}
                        <p>Aucun résultat</p>
                    {/if} <!-- End if sizeof statParDate-->
                {else}
                <h4>Les trois derniers mois </h4>
                <table id="rounded-corner" summary="2007 Major IT Companies' Profit">
                    <thead>
                        <tr>
                            <th scope="col" class="rounded">Date : {$date->months[0]}/{$date->year[0]}</th>
                            <th scope="col" class="rounded">Formule</th>
                            <th scope="col" class="rounded">Nombre d'annonces validées</th>
                            <th scope="col" class="rounded-q4">Total €</th>
                        </tr>
                    </thead>
                    <tbody>
                    <!-- CURRENT MONTH-->
                        {assign $nbrPhoto = 0}
                        {assign $totalNombreDetail = 0}
                        {assign $totalEuroDetail = 0}
                        {assign $j = 1}
                        {foreach $statCurrentMonth['tarif'] as $item}
                            {assign $totalNombreDetail += $item->nombre}
                            {assign $totalEuroDetail   += $item->Occas_Montantpaye * $item->nombre}
                            {foreach $statCurrentMonth['photo'] as $itemPhoto}
                                {if $itemPhoto->Occas_Montantpaye == $item->Occas_Montantpaye}
                                    {assign $nbrPhoto = $itemPhoto->nombre}
                                    {break}
                                {/if}
                            {/foreach}
                          <tr class="{if $j%2 == 0 }hblue{/if}">
                              <td>&nbsp;</td>
                              <td>{$item->titre}</td>
                              <td>{$item->nombre} (Photos : {$nbrPhoto})</td>
                              <td>{$item->Occas_Montantpaye * $item->nombre}</td>
                          </tr>
                          {assign $j++}
                        {/foreach}
                         
                          <tr>
                              <td>&nbsp;</td>
                              <td><b>Total : </td>
                              <td><b>{$totalNombreDetail}</b></td>
                              <td><b>{$totalEuroDetail}</b></td>
                          </tr>
                      </tbody>
                    </table>
                     <!-- /CURRENT MONTH-->
                    <table id="rounded-corner" summary="2007 Major IT Companies' Profit">
                    <thead>
                        <tr>
                            <th scope="col" class="rounded">Date : {$date->months[1]}/{$date->year[1]}</th>
                            <th scope="col" class="rounded">Formule</th>
                            <th scope="col" class="rounded">Nombre d'annonces validées</th>
                            <th scope="col" class="rounded-q4">Total €</th>
                        </tr>
                    </thead>
                    <tbody>
                     <!-- MONTH MINUS ONE-->

                        {assign $nbrPhoto = 0}
                        {assign $totalNombreDetail1 = 0}
                        {assign $totalEuroDetail1 = 0}
                        {assign $j = 1}
                        {foreach $stat1['tarif'] as $item}
                            {assign $totalNombreDetail1 += $item->nombre}
                            {assign $totalEuroDetail1   += $item->Occas_Montantpaye * $item->nombre}
                            {foreach $stat1['photo'] as $itemPhoto}
                                {if $itemPhoto->Occas_Montantpaye == $item->Occas_Montantpaye}
                                    {assign $nbrPhoto = $itemPhoto->nombre}
                                    {break}
                                {/if}
                            {/foreach}
                          <tr class="{if $j%2 == 0 }hblue{/if}">
                              <td>&nbsp;</td>
                              <td>{$item->titre}</td>
                              <td>{$item->nombre} (Photos : {$nbrPhoto})</td>
                              <td>{$item->Occas_Montantpaye * $item->nombre}</td>
                          </tr>
                          {assign $j++}
                        {/foreach}
                         
                          <tr>
                              <td>&nbsp;</td>
                              <td><b>Total : </td>
                              <td><b>{$totalNombreDetail1}</b></td>
                              <td><b>{$totalEuroDetail1}</b></td>
                          </tr>
                          </tbody>
                </table>
                <table id="rounded-corner" summary="2007 Major IT Companies' Profit">
                    <thead>
                        <tr>
                            <th scope="col" class="rounded">Date : {$date->months[2]}/{$date->year[2]}</th>
                            <th scope="col" class="rounded">Formule</th>
                            <th scope="col" class="rounded">Nombre d'annonces validées</th>
                            <th scope="col" class="rounded-q4">Total €</th>
                        </tr>
                    </thead>
                    <tbody>
                      <!-- /MONTH MINUS ONE-->

                      <!-- MONTH MINUS TWO-->
                        {assign $nbrPhoto = 0}
                        {assign $totalNombreDetail2 = 0}
                        {assign $totalEuroDetail2 = 0}
                        {assign $j = 1}
                        {foreach $stat2['tarif'] as $item}
                            {assign $totalNombreDetail2 += $item->nombre}
                            {assign $totalEuroDetail2   += $item->Occas_Montantpaye * $item->nombre}
                            {foreach $stat2['photo'] as $itemPhoto}
                                {if $itemPhoto->Occas_Montantpaye == $item->Occas_Montantpaye}
                                    {assign $nbrPhoto = $itemPhoto->nombre}
                                    {break}
                                {/if}
                            {/foreach}
                          <tr class="{if $j%2 == 0 }hblue{/if}">
                              <td>&nbsp;</td>
                              <td>{$item->titre}</td>
                              <td>{$item->nombre} (Photos : {$nbrPhoto})</td>
                              <td>{$item->Occas_Montantpaye * $item->nombre}</td>
                          </tr>
                          {assign $j++}
                        {/foreach}
                         
                          <tr>
                              <td>&nbsp;</td>
                              <td><b>Total : </td>
                              <td><b>{$totalNombreDetail2}</b></td>
                              <td><b>{$totalEuroDetail2}</b></td>
                          </tr>

                      <!-- /MONTH MINUS TWO-->

                    </tbody>
                </table>
                
                <br />
                <table id="rounded-corner" summary="2007 Major IT Companies' Profit">
                    <thead>
                        <tr>
                            <th scope="col" class="rounded">Total des totaux</th>
                            <th scope="col" class="rounded">Nombre d'annonces</th>
                            <th scope="col" class="rounded-q4">Total €</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                              <td>&nbsp;</td>
                              <td><b>{$totalNombreDetail + $totalNombreDetail1 + $totalNombreDetail2}</b></td>
                              <td><b>{$totalEuroDetail + $totalEuroDetail1 + $totalEuroDetail2}</b></td>
                          </tr>
                    </tbody>
                </table>
                {/if} <!-- End if $datedebut $ dateFin-->
                <br />
            </div><!-- end of right content-->
        </div>   <!--end of center content -->               

        <div class="clear"></div>
    </div> <!--end of main content-->
	
    
    <div class="footer">
    </div>

</div>

{literal} 
    <script type="text/javascript">
        $(function(){
            $("#datepicker1").datepicker({dateFormat: 'dd/mm/yy'});
            $("#datepicker2").datepicker({dateFormat: 'dd/mm/yy'});

            // clic sur le bouton trier
            $('#trier').click(function () {
                debut = $('#datepicker1').val();
                fin   = $('#datepicker2').val();
                if (debut != '' && fin != '')
                {
                    document.forms["trie"].submit();
                }
                else
                {
                    $('#datepicker1').css('border', 'solid 1px #8D989B');
                    $('#datepicker2').css('border', 'solid 1px #8D989B');
                    if (debut == '')
                    {
                        $('#datepicker1').css('border', 'solid 1px #DD1616');
                    }
                    if (fin == '')
                    {
                        $('#datepicker2').css('border', 'solid 1px #DD1616');
                    }
                    $('#error').show();
                    return false;
                }
                
                
            });
        });
    </script>
    <style type="text/css">
        p#btn-trie {position:relative;top:-49px;right:201px;}
        p#error {font-size:0.8em;color:#DD1616;}
    </style>
{/literal}
